Stop using pango_split_file_list
authorMatthias Clasen <mclasen@redhat.com>
Sat, 26 Mar 2016 22:18:50 +0000 (18:18 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 26 Mar 2016 22:19:37 +0000 (18:19 -0400)
Add a copy of this deprecated utility in gtkutils.c and use
it instead of the pango API.

gtk/Makefile.am
gtk/gtkmodules.c
gtk/gtkutils.c
gtk/gtkutilsprivate.h
gtk/queryimmodules.c

index 25729d04dc5a2ef3e1aee5f591bc9778361f7576..0e92feb3fe658f359b9d421ed9f8fa721aa2e807 100644 (file)
@@ -1511,7 +1511,7 @@ bin_PROGRAMS = \
        gtk-query-settings \
        gtk-launch
 
-gtk_query_immodules_3_0_SOURCES = queryimmodules.c
+gtk_query_immodules_3_0_SOURCES = queryimmodules.c gtkutils.c
 gtk_query_immodules_3_0_LDADD =                \
        libgtk-3.la                             \
        $(top_builddir)/gdk/libgdk-3.la         \
index ace1d10f597e7b63c04b3a4017bf036b8a7ac7eb..0aaedae5811e0699dae538376e1e60322902c886 100644 (file)
@@ -26,6 +26,7 @@
 #include "gtkprivate.h"
 #include "gtkmodulesprivate.h"
 #include "gtkintl.h"
+#include "gtkutilsprivate.h"
 
 #include <gmodule.h>
 
@@ -77,9 +78,7 @@ get_module_path (void)
 
   g_free (default_dir);
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  result = pango_split_file_list (module_path);
-G_GNUC_END_IGNORE_DEPRECATIONS
+  result = gtk_split_file_list (module_path);
   g_free (module_path);
 
   return result;
@@ -419,10 +418,8 @@ load_modules (const char *module_str)
 
   GTK_NOTE (MODULES, g_message ("Loading module list: %s", module_str));
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  module_names = pango_split_file_list (module_str);
-G_GNUC_END_IGNORE_DEPRECATIONS
-  for (i = 0; module_names[i]; i++) 
+  module_names = gtk_split_file_list (module_str);
+  for (i = 0; module_names[i]; i++)
     module_list = load_module (module_list, module_names[i]);
 
   module_list = g_slist_reverse (module_list);
index a6818b2bca2e904715c5c1b7841ea877149d72af..69c4ccbaff128d7c9534bcf05ec17f7c319beb6d 100644 (file)
@@ -191,3 +191,76 @@ gtk_read_line (FILE *stream, GString *str)
 
   return (n_read > 0) ? lines : 0;
 }
+
+char *
+gtk_trim_string (const char *str)
+{
+  int len;
+
+  g_return_val_if_fail (str != NULL, NULL);
+
+  while (*str && g_ascii_isspace (*str))
+    str++;
+
+  len = strlen (str);
+  while (len > 0 && g_ascii_isspace (str[len - 1]))
+    len--;
+
+  return g_strndup (str, len);
+}
+
+char **
+gtk_split_file_list (const char *str)
+{
+  int i = 0;
+  int j;
+  char **files;
+
+  files = g_strsplit (str, G_SEARCHPATH_SEPARATOR_S, -1);
+
+  while (files[i])
+    {
+      char *file = gtk_trim_string (files[i]);
+
+      /* If the resulting file is empty, skip it */
+      if (file[0] == '\0')
+        {
+          g_free (file);
+          g_free (files[i]);
+
+          for (j = i + 1; files[j]; j++)
+            files[j - 1] = files[j];
+
+          files[j - 1] = NULL;
+
+          continue;
+        }
+
+#ifndef G_OS_WIN32
+      /* '~' is a quite normal and common character in file names on
+       * Windows, especially in the 8.3 versions of long file names, which
+       * still occur now and then. Also, few Windows user are aware of the
+       * Unix shell convention that '~' stands for the home directory,
+       * even if they happen to have a home directory.
+       */
+      if (file[0] == '~' && file[1] == G_DIR_SEPARATOR)
+        {
+          char *tmp = g_strconcat (g_get_home_dir(), file + 1, NULL);
+          g_free (file);
+          file = tmp;
+        }
+      else if (file[0] == '~' && file[1] == '\0')
+        {
+          g_free (file);
+          file = g_strdup (g_get_home_dir ());
+        }
+#endif
+
+      g_free (files[i]);
+      files[i] = file;
+
+      i++;
+    }
+
+  return files;
+}
index e5d34bbce0f7e8443ecca0ce37d2ed4a64f48025..a498c74fd9ec910d41a825a507c128090675f494 100644 (file)
@@ -10,6 +10,8 @@ gboolean        gtk_scan_string         (const char     **pos,
 gboolean        gtk_skip_space          (const char     **pos);
 gint            gtk_read_line           (FILE            *stream,
                                          GString         *str);
+char *          gtk_trim_string         (const char      *str);
+char **         gtk_split_file_list     (const char      *str);
 
 G_END_DECLS
 
index 83052e805c52b3bcdfbdbf006cf48ceb4531f52e..e9978fd3227852d34f56d0858770ccedc176dd31 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "gtk/gtkimcontextinfo.h"
 #include "gtk/gtkversion.h"
+#include "gtk/gtkutilsprivate.h"
 
 #include "gtk/deprecated/gtkrc.h"
 
@@ -189,9 +190,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 
       g_string_append_printf (contents, "# ModulesPath = %s\n#\n", path);
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-      dirs = pango_split_file_list (path);
-G_GNUC_END_IGNORE_DEPRECATIONS
+      dirs = gtk_split_file_list (path);
       dirs_done = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
 
       for (i = 0; dirs[i]; i++)